
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>留言板</title>
    <link href="./Tpl/css/bootstrap.min.css" rel="stylesheet">
  </head>

  <body>

    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">留言板</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">

          <?php if(isset($_SESSION['username'])){ ?>
              <div class="navbar-form navbar-right">
              <button class="btn btn-primary"><?php echo $_SESSION['username']; ?></button>
              <a href="./loginout.php" class="btn btn-success">退出</a>
            </div>
          <?php }else{ ?>
          <form method="post" action="./login.php" class="navbar-form navbar-right">
            <div class="form-group">
              <input type="text" name="username" placeholder="Email" class="form-control">
            </div>
            <div class="form-group">
              <input type="password" name="password" placeholder="Password" class="form-control">
            </div>
            <button type="submit" class="btn btn-success">登录</button>
            <a href="./reg.php" class="btn btn-success">注册</a>
          </form>
          <?php } ?>
          
        </div><!--/.navbar-collapse -->
      </div>
    </nav>

    <div class="container" style="margin-top:100px;">
      <!-- Example row of columns -->
      <div class="row">
        <?php if (isset($_SESSION['info'])) { ?>
            <div id="info" class="alert alert-danger" role="alert">
            <strong><?php echo $_SESSION['info']; ?></strong>  
          </div>
        <?php } ?>
        
      	<!-- 循环数据库 -->
      	<?php foreach ($list as $k => $row) { ?>
	      <div class="alert alert-success" role="alert">
	        <strong><?php echo $row['username'] ?> : </strong><?php echo $row['content'] ?>（<?php echo Ctime($row['ctime']) ?>）

	        <div class="box" style="float:right;margin-top:-10px">
	        	<a href="./del.php?id=<?php echo $k  ?>" class="btn btn-danger">删除</a>
	        	<a href="./edit.php?id=<?php echo $k  ?>" class="btn btn-primary">修改</a>
	        </div>
	      </div>
	     <?php } ?>
      </div>
      <div class="row">
        <nav aria-label="...">
        <ul class="pagination">
          <!-- 在第一页的不输出上一页 -->
          <?php if($p!=1){?>

            <li>
                <a href="./index.php?p=<?php echo $p-1 ?>">
                <span>上一页<span class="sr-only"></span></span>
                </a>
            </li>

          <?php } ?>

          <!-- 总页数少于5页 -->
          <?php if($num<5){ ?>
              <?php for ($i=1; $i <= $num; $i++) {  ?>
          
                <li class="<?php if($i==$p){ echo "active";} ?>">
                  <a href="./index.php?p=<?php echo $i ?>">
                  <span><?php echo $i ?><span class="sr-only"></span></span>
                  </a>
                </li>
              
              <?php } ?>
              
          <?php }else{ ?>
              <li>
                  <a href="javascript:;">
                  <span>...<span class="sr-only"></span></span>
                  </a>
              </li>
              <?php for ($i=$p-2; $i <= $p+2; $i++) {  ?>
          
                <li class="<?php if($i==$p){ echo "active";} ?>">
                  <a href="./index.php?p=<?php echo $i ?>">
                  <span><?php echo $i ?><span class="sr-only"></span></span>
                  </a>
                </li>
              
              <?php } ?>
              <li>
                  <a href="javascript:;">
                  <span>...<span class="sr-only"></span></span>
                  </a>
              </li>

          <?php } ?>

          <!-- //要最后一页的时候不输出下一页 -->
          <?php if($p!=$num){ ?>
              <li>
                  <a href="./index.php?p=<?php echo $p+1 ?>">
                  <span>下一页<span class="sr-only"></span></span>
                  </a>
              </li>
          <?php } ?>

          
        </ul>
      </nav>
        
      </div>
      <div class="row">
      	<form class="form-inline" action="./add.php" method="post">
		  <div class="form-group">
		    <label for="exampleInputName2">昵称</label>
		    <input type="text" class="form-control" id="exampleInputName2" name="username" placeholder="昵称">
		  </div>
		  <button type="submit" class="btn btn-success">发布</button>
		  <div class="form-group" style="display:block">
		    <textarea name="content" style="width:100%;margin-top:20px" class="form-control" rows="3"></textarea>
		  </div>
		  
		  
		</form>
    
      </div>

      <hr>

      <footer>
        <p>&copy; 2016 Company, Inc.</p>
      </footer>
    </div> <!-- /container -->


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>

    <script type="text/javascript">

        $(function  () {
            setTimeout(run,2000);

            function run () {
              $('#info').slideUp();
            }
        })
    </script>
  </body>
</html>
